package P3;

import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

import NIOCommunication.NIOProcessor;
import NIOCommunication.NIOServerSocketContext;
import NIOCommunication.NIOSocketContext;

public class CoordinatorServerContext extends NIOServerSocketContext
{
    private Coordinator mCoordinator;
	public CoordinatorServerContext(Coordinator coordinator, NIOProcessor processor, ServerSocketChannel serverSocketChannel)
	{
		super(processor, serverSocketChannel);
                mCoordinator = coordinator;
	}

	public CoordinatorServerContext(Coordinator coordinator, NIOProcessor processor, int port)
	{
		super(processor, port);
                mCoordinator = coordinator;
	}

	public CoordinatorServerContext(Coordinator coordinator, NIOProcessor processor)
	{
		super(processor);
                mCoordinator = coordinator;
	}
	
	@Override
	public void OnNewConnection(SocketChannel client)
	{
		WorkerInterface clientContext;
		clientContext = new WorkerInterface(mCoordinator, mNIOProcessor, client);
                mCoordinator.OnNewWorkerConnection(clientContext);
	}
}
